package com.example.gray.mapper;

import com.example.gray.entity.LogDate;
import com.example.gray.entity.LogIp;
import com.example.gray.entity.OpLog;
import com.example.gray.entity.TimeAccess;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Gray 2021/12/28-18:10
 */
@Mapper
public interface OpLogMapper {
    @Select("select * from op_log")
    List<OpLog> getAllLog();

    @Select("select * from op_log where userId like concat('%',#{id},'%')")
    List<OpLog> getLogById(Integer id);

    @Select("select * from op_log where ipAddress = #{ip}")
    List<OpLog> getLogByIp(String ip);

    @Select("select * from op_log where opDate between #{D1} and #{D2} order by count(ipAddress) desc")
    List<OpLog> getLogByTime(String D1,String D2);

    @Select("select ipAddress,count(*) as count from op_log where opDate between #{D1} and #{D2} group by ipAddress order by count(*) desc")
    List<LogIp> getTop10(String D1,String D2);

    @Select("select opDate,count(*) as count from op_log where opDate between #{s} and #{e} group by opDate")
    List<LogDate> orderByDate(String s, String e);

    @Select("SELECT date_format(opDate,'%H')as hour,COUNT(*)as count FROM `op_log` WHERE 1 GROUP BY date_format(opDate,'%H') ORDER BY date_format(opDate,'%H')")
    List<TimeAccess> getTimeZone();

    @Insert("insert into op_log(ipAddress,userId,opDate,opMethods) values(#{ipAddress},#{userId},#{opDate},#{opMethods})")
    Integer insertLog(OpLog log);

    @Delete("delete from op_log where logId = #{logId}")
    Integer deleteLog(Integer logId);

    @Update("update op_log set ipAddress=#{ipAddress},userId=#{userId},opDate=#{opDate},opMethods=#{opMethods} where logId = #{logId}")
    Integer updateLog(OpLog log);
}
